
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using Swaf;
using Swaf.BizObj;
using Swaf.BizRule;
using Swaf.Gui;
using Swaf.Security;

using UserLogin.Gui;
using Syrinx.Gui;
namespace UserManagement.Gui
{
	public class UserGroupAppFunctionBizProc : Swaf.Gui.BaseBusinessProcess
	{
		public UserGroupAppFunctionBizProc(ActiveBizProc procState)
			: base(procState)
		{
		}

		protected override void setupRuleNames()
		{
			base.m_getMasterBizObjListRule = "getSpecificCompanyAppFunctions";
			//base.m_updateBizObjRule = "updateUserGroupAppFunctions";
		}

        //protected override void getBizObjList()
        //{
        //    IBizObj userGroup = m_procState.get("userGroup") as IBizObj;
        //    Debug.Assert(userGroup != null);
        //    m_bizobjs = userGroup.get("appPrivileges") as IBizObjList;
        //    setupMasterBizObjList();
        //}

		protected override void prepareForMasterList(ref IBizObjList masterList, ref IBizObjList baseList)
		{
			Debug.Assert(masterList != null);
			Debug.Assert(baseList != null);

			foreach (IBizObj obj in baseList)
			{
				IBizObj masterObj = masterList.search("id", obj.get("id"));
				if (masterObj != null)
				{
					obj.put("description", masterObj.get("description"));
					obj.put("depth", masterObj.get("depth"));
				}
				else
				{
					//TODO: Deal with the fact that there is a privilege set for something not in master.  this can
					//happen when a dynamic app function is set for a user and then that element is removed.
				}
			}
		}

        protected override object[] getMasterBizObjListBizRuleParams(object mlpid)
        {
            return new object[] { mlpid, null };
        }

		protected override object[] getUpdateBizRuleParameters(IBizObj bizObj)
		{
			IBizObj userGroup = m_procState.get("userGroup") as IBizObj;
			return new object[] { userGroup.KeyValue, bizObj };
		}

		protected override object[] getBizObjListRuleParameters(object parentId, IBizObj filterSort)
		{
			return new object[] { parentId, null };
		}

		public override Privileges CurrentEditPrivilege { get { return CurrentPrincipal.getPrivilege("AppFunctions.ManageUsers"); } }
		
	}
}
